<?php
/* Start php session */
session_start();

/* Autoload */
function __autoload($className) {
  if (!class_exists($className, false) && file_exists(dirname(__FILE__).'/../classes/'.$className.'.php'))
    require_once(dirname(__FILE__).'/../classes/'.$className.'.php');
}

/* Load settings */
if (file_exists(dirname(__FILE__).'/settings.php'))
  include_once('settings.php');
else
  die('The settings.php file doesn\'t exist! You may need to rename settings.example.php to settings.php and then configure it.');

/* Connect to database */
define('_DB_SERVER_', $dbhost); define('_DB_USER_', $dbuser); define('_DB_PASSWD_', $dbpass); define('_DB_TYPE_', 'MySQL'); define('_DB_NAME_', $dbname); define('_DB_PREFIX_','');
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('<h1>The database doesn\'t work! The finger for the database! </h1><p>Error connecting to database: ' . mysql_error().'</p>');
mysql_select_db($dbname);

/* Include some basic functions */
include_once('functions.misc.php');

/* Load all configuration keys */
Configuration::loadConfiguration();

/* Auto detect new sql files and update the database structure. */
$autoDbUp = new AutoDbUp(dirname(__FILE__).'/../db/autodbup/');
$autoDbUp->upgrade();

/* Check for notice to be accepted */
$notice_msg = '<a href="'.BASE_URL.'notice.php">Please read this NOTICE before using this website.</a>';
if (!isset($_SESSION['start'])) {
  Tools::setNotice($notice_msg);
  $_SESSION['start'] = time();
 }

/* Flashes */
$confirms = array();
$errors = array();
Tools::getFlash($confirms);
Tools::getFlash($errors, true);
Tools::getNotice($notice, false);
?>